#!/bin/bash

# jar名称
jar_name="cloud-code-core-service-1.0-SNAPSHOT.jar"
jar_home="/home/ubuntu/home/jar"

# 先停止之前jar 进程
pid=$(ps -ef | grep "$jar_name" | grep -v grep | awk '{print $2}')
if [ ! -z "$pid" ]; then
  echo "Terminating existing process: $pid"
  kill "$pid"
  # Optionally wait for the process to be killed
  # wait "$pid"
fi

# Navigate to the directory where the jar file is located
cd /path/to/jar/

# 启动jar包
echo "Starting $jar_name..."
nohup /opt/jdk-17.0.6/bin/java -jar "$jar_home/$jar_name" > app.log 2>&1 &

echo "Application started successfully."
